<extend name="Public/base" />

<block name="body">
    <include file="Public:sui" />
    <!-- 标题栏 -->
    <div class="main-title">
        <h2>{$meta_title}</h2>
    </div>
    <eq name="pay.status" value="0">
    <div class="cf">
        <div class="fl">
            <button class="btn" data-toggle="modal" data-target="#myModal" data-width="large">重新选课</button>
        </div>
    </div>
    </eq>

    <!-- 数据列表 -->
    <div class="data-table table-striped">
        <table class="">
            <thead>
            <tr>
                <th class="row-selected" style="width: 8%;">序号</th>
                <th class="">课程内容</th>
                <th class="">学习内容</th>
                <th class="">教学重点</th>
                <th class="">时间</th>
                <th class="">授课老师</th>
            </tr>
            </thead>
            <tbody>
            <notempty name="_list">
                <volist name="_list" id="vo">
                    <tr>
                        <td>{$i}</td>
                        <td>{$vo.content}</td>
                        <td>{$vo.learning_content}</td>
                        <td>{$vo.teaching_emphasis}</td>
                        <td><input type="text" class="text" id="class_time_{$vo.id}" style="width: 120px;" name="class_time[]" value="{$vo.class_time|time_format}"  <eq name="vo.step" value="3">disabled</eq> ></td>
                        <td>
                            <select name="teacher_{$vo.id}" id="teacher_{$vo.id}" style="width: 100px;" onchange="_saveData({$vo.id})" <eq name="vo.step" value="3">disabled</eq>>
                            <volist name="_teacher" id="tea" key="k">
                                <option value="{$tea.uid}" <php>if($tea['uid']==$vo['teacher_id'])echo 'selected="selected"';</php> >{$tea.nickname}</option>
                            </volist>
                            </select>
                        </td>
                    </tr>
                </volist>
                <else/>
                <td colspan="14" class="text-center"> aOh! 暂时还没有内容! </td>
            </notempty>
            </tbody>
        </table>
    </div>
    <div class="page">
        {$_page}
    </div>


    <!-- Modal-->
    <div id="myModal" tabindex="-1" role="dialog" data-hasfoot="false" class="sui-modal hide fade">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" data-dismiss="modal" aria-hidden="true" class="sui-close">×</button>
                    <h4 id="myModalLabel" class="modal-title">《{$pay.course_id|_getCourseTitle}》</h4>
                </div>
                <div class="modal-body">
                    <table class="sui-table table-bordered" style="font-size: 12px;">
                        <thead>
                        <tr>
                            <th style="width: 18px;">＃</th>
                            <th>课程</th>
                            <th>学习内容</th>
                            <th>教学重点</th>
                        </tr>
                        </thead>
                        <tbody>
                        <volist name="plan" id="vo">
                        <tr>
                            <td><input class="ids" type="checkbox" name="id[]" value="{$vo.id}"  <php>if(in_array($vo['id'], $idarray))echo 'checked';</php> /></td>
                            <td>{$vo.explain}</td>
                            <td>{$vo.learning_content}</td>
                            <td>{$vo.teaching_emphasis}</td>
                        </tr>
                        </volist>
                        </tbody>
                    </table>

                </div>
                <div class="modal-footer">
                    <button type="button" data-ok="modal" class="sui-btn btn-primary btn-large" id="_xuanke">确 定</button>
                    <button type="button" data-dismiss="modal" class="sui-btn btn-default btn-large">取 消</button>
                </div>
            </div>
        </div>
    </div>
</block>

<block name="script">
    <script src="__STATIC__/thinkbox/jquery.thinkbox.js"></script>

    <script type="text/javascript">

        <volist name="_list" id="vo">
            laydate.render({
                elem: '#class_time_{$vo.id}' ,
                type: 'datetime',
                format: 'yyyy-MM-dd HH:mm',//可任意组合
                done: function(value, date){ //监听日期被切换
                    document.getElementById("class_time_{$vo.id}").value = value;
                    _saveData({$vo.id});
                }
            });
        </volist>

        function _saveData(id) {
            var class_time = $("#class_time_"+id).val();
            var teacher = $("#teacher_"+id).val();
            $.ajax({
                type: 'POST',
                url: "{:U('Teaching/ajaxSaveData')}",
                data: "id="+id+"&class_time="+class_time+"&teacher="+teacher,
                success: function (res) {
                    if(res.status==1){
                    }else{
                        updateAlert('服务器繁忙，请重试!');
                        setTimeout(function(){
                            $('#top-alert').find('button').click();
                        },2000);
                    }
                }
            });
        }

        $(function(){
            $("input[type='checkbox']").click(function() {
                var len = $("input[type='checkbox']:checked").length;
                if(len>{$maxnum}){
                    alert("选中课数不能大于{$maxnum}节课！");
                    $(this).prop("checked", false);
                }
            });
        })

        $("#_xuanke").click(function(){
            var chk_value =[];//定义一个数组
            $('input[type="checkbox"]:checked').each(function(){
                chk_value.push($(this).val());
            });
            var vals = chk_value.join(",");
            $.ajax({
                type: 'POST',
                url: "{:U('ajaxUpdateClass_plan')}",
                data: "payid={$pay.id}&course_plan_ids={$course_plan_ids}&selected_ids="+vals,
                success: function (res) {
                    if(res.status==1){
                        window.location.reload();
                    }else{
                        alert("服务器繁忙，请稍后再试！");
                    }
                }
            });
        });

        //导航高亮
        highlight_subnav('{:U('Teaching/index')}');
    </script>
</block>
